package com.gupaoedu.mybatis.gp;

import com.gupaoedu.mybatis.beans.Test;
import com.gupaoedu.mybatis.gp.config.GpConfiguration;
import com.gupaoedu.mybatis.gp.executor.Executor;
import com.gupaoedu.mybatis.gp.executor.ExecutorFactory;
import com.gupaoedu.mybatis.gp.plugin.InterceptorChain;
import com.gupaoedu.mybatis.gp.session.GpSqlSession;
import com.gupaoedu.mybatis.my.TestMapper;

/**
 * Created by James on 2017-07-05.
 * From 咕泡学院出品
 * 老师咨询 QQ 2904270631
 */
public class BootStrap {
    public static void main(String[] args) throws Exception {
        start();
    }

    private static void start() throws Exception {
        InterceptorChain interceptorChain = new InterceptorChain();
        GpConfiguration configuration = new GpConfiguration(interceptorChain);
        configuration.setScanPath("com.gupaoedu.mybatis.gp.config.mappers");
        configuration.build();
        Executor executor = ExecutorFactory.get(ExecutorFactory.ExecutorType.CACHING.name(),configuration);
        executor = (Executor)interceptorChain.pluginAll(executor);
        GpSqlSession sqlSession = new GpSqlSession(configuration, executor);
        TestMapper testMapper = sqlSession.getMapper(TestMapper.class);
        long start = System.currentTimeMillis();
        Test test = testMapper.selectByPrimaryKey(1);
        System.out.println(test);
        System.out.println("cost:"+ (System.currentTimeMillis() -start));
    }
}
